<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Allocator Data File List</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/datepicker/datepicker.js"></script>
	<!-- 页面特效 -->
	<jsp:include page="/beshs/res-refer/page-effect-reference.jsp" />
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
  </head>
  <script type="text/javascript">
  function uploadMeterDataFile() {
		loadNewModal(path+"beshs/assignMeterDataFileAction!intialDataFileUpload.do?date="+new Date(),"Upload the allocation table data file","170px","450px");
	}
  	
  	function showUploadDetail(dataFileUID) {
  		window.location = path + "beshs/assignMeterDataFileAction!queryUploadDetail.do?dataFileUID="+dataFileUID
				+"&date="+new Date();
  	}
  	
  	function prevewTxtContent(dataFileUID) {
  		window.location = path + "beshs/assignMeterDataFileAction!queryUploadDetail.do?dataFileUID="+dataFileUID
  				+"&detailType=txtContent"
  				+"&date="+new Date();
  	}
  
  	function downloadDataFile(dataFileUID) {
  		window.location = path+"beshs/assignMeterDataFileAction!downloadAttachFile.do?dataFileUID="+dataFileUID+"&date="+new Date();
  	}
  	
  	function deleteDataFile(dataFileUID) {
  		Dialog.confirm("Are you sure to delete this item?", function() {
  			$.getJSON(path+"beshs/assignMeterDataFileActionJson!deleteDataFileByUID.do?date="+new Date(), {
  				dataFileUID: dataFileUID
  	  		}, function(data) {
  	  			if(data.success) {
  	  				Dialog.alert("Successful Operation！", function() {
  	  					window.location = path + "beshs/assignMeterDataFileAction!queryDataFilePage.do?date="+new Date();
  	  				});
  	  			} else {
  	  				Dialog.alert("System error, please contact adminitrator！");
  	  			}
  	  		});
  		});
  	}
  	
  	$(function(){
  		$("input[name='query']").click(function(){
  			var fileName = $("input[name='fileName']").val();
  			var startDate = $("input[name='startDate']").val();
  			var endDate = $("input[name='endDate']").val();
  			window.location = path + "beshs/assignMeterDataFileAction!queryDataFilePage.do?fileName="+encodeURIComponent(fileName)
  					+"&startDate=" + startDate
  					+"&endDate=" + endDate
  					+"&date="+new Date();
  		});
  		
  		$("input[name='add']").click(function(){
  			uploadMeterDataFile();
  		});
  	});
  </script>
  <body>
  	<div class="content_all">
	  	<!--查询条件-->
	  	<div class="search">
	    	<form action=""><table cellpadding="0" cellspacing="0">
	      		<tr>
	      			<th>File Name：</th>
			        <td><input name="fileName" value="<s:property value='fileName' />" type="text" class="s_input" /></td>
			        <th>Upload Date：</th>
			        <td>
			        <input id="uploadDate_startDate" name="startDate" class="Wdate" value="<s:date name='startDate' format='yyyy-MM-dd' nice='false' />" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" />
			        
<%-- 			        	<input name="startDate" type="text" class="s_input" id="uploadDate_startDate" value="<s:date name='startDate' format='yyyy-MM-dd' nice='false' />" onclick="selectDate(this,'yyyy-MM-dd')" readonly/> --%>
<%--           				<img src="<%=basePath%>resources/datepicker/calendar.jpg" onclick="txtSelectDate('uploadDate_startDate','yyyy-MM-dd')"/> --%>
          				To
          				<input id="uploadDate_endDate" name="endDate" class="Wdate" value="<s:date name='endDate' format='yyyy-MM-dd' nice='false' />" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" />
          				
<%--           				<input name="endDate" type="text" class="s_input" id="uploadDate_endDate" value="<s:date name='endDate' format='yyyy-MM-dd' nice='false' />" onclick="selectDate(this,'yyyy-MM-dd')" readonly/> --%>
<%--           				<img src="<%=basePath%>resources/datepicker/calendar.jpg" onclick="txtSelectDate('uploadDate_endDate','yyyy-MM-dd')"/> --%>
			        </td>
			        <td><input name="query" type="button" value="Query" class="s_btn" />
			        	<input name="reset" type="reset" value="Reset" class="s_btn" />
			        	<s:if test="superManager.contains(#session.user.userID) 
								|| loginUserRoleIDList.contains(sysadmin) 
								|| loginUserRoleIDList.contains(sysShareManager)">
							<input name="add" type="button" value="Upload File" class="s_btn" />
						</s:if>
	        		</td>
	      		</tr>
	    	</table></form>
	  	</div>
	  	<!--查询列表-->
	  	<div class="search_table_all">
	    	<table class="search_table" cellspacing="0" cellpadding="0">
	      		<thead>
	        		<tr>
		          		<th style="width:50px;">Serial No.</th>
			          	<th>File Name</th>
			          	<th>File Size</th>
			          	<th>Record Number of Allocator</th>
			          	<th>Allocator Upload Number</th>
			          	<th>Record Number of Heat Meter</th>
			          	<th>Heat Meter Upload Number</th>
			          	<th>Upload Date</th>
			          	<th>Submitters</th>
			          	<th>Operation</th>
	        		</tr>
	      		</thead>
	      		<tbody>
	      			<s:iterator value="dataFilePage.list" var="dataFile" status="status">
	      				<tr>
		          			<td><s:property value="#status.index+1" /></td>
		          			<td><s:property value="#dataFile.fileName" /></td>
		          			<td>
		          				<s:if test="#dataFile.fileSize<1024">
		          					<s:text name="fmt.number.precision.zero">
					          			<s:param value='#dataFile.fileSize' />
					          		</s:text>字节
		          				</s:if>
		          				<s:elseif test="#dataFile.fileSize>1024 && #dataFile.fileSize<1024*1024">
		          					<s:text name="fmt.number.precision.three">
					          			<s:param value='#dataFile.fileSize/1024' />
					          		</s:text>KB
		          				</s:elseif>
		          				<s:else>
		          					<s:text name="fmt.number.precision.three">
					          			<s:param value='#dataFile.fileSize/1024/1024' />
					          		</s:text>MB
		          				</s:else>
		          			</td>
		          			<td><s:property value="#dataFile.amRecordNum" /></td>
		          			<td><s:property value="#dataFile.amSuccessNum" /></td>
		          			<td><s:property value="#dataFile.hmRecordNum" /></td>
		          			<td><s:property value="#dataFile.hmSuccessNum" /></td>
		          			<td>
		          				<s:date name='#dataFile.uploadDate' format='yyyy-MM-dd HH:mm:ss' nice='false' />
		          			</td>
		          			<td><s:property value="#dataFile.uploadMan" /></td>
		          			<td><a href="javascript:showUploadDetail('<s:property value='#dataFile.id' />')">[Check]</a>&nbsp;
		          				<a href="javascript:prevewTxtContent('<s:property value='#dataFile.id' />')">[Preview]</a>&nbsp;
		          				<a href="javascript:downloadDataFile('<s:property value='#dataFile.id' />')">[DownLoad]</a>
		          				<s:if test="superManager.contains(#session.user.userID) 
										|| loginUserRoleIDList.contains(sysadmin) 
										|| loginUserRoleIDList.contains(sysShareManager)">
									&nbsp;<a href="javascript:deleteDataFile('<s:property value='#dataFile.id' />')">[Delete]</a>
								</s:if>
		          			</td>
		        		</tr>
	      			</s:iterator>
	      		</tbody>
	    	</table>
	  	</div>
	  	<!--操作按钮&分页-->
	  	<script type="text/javascript">
	  		function pageUp(pageIndex) {
	  			var fileName = $("input[name='fileName']").val();
	  			var startDate = $("input[name='startDate']").val();
	  			var endDate = $("input[name='endDate']").val();
	  			window.location = path + "beshs/assignMeterDataFileAction!queryDataFilePage.do?pageIndex="+(pageIndex-1)
	  					+"&fileName="+encodeURIComponent(fileName)
	  					+"&startDate=" + startDate
  						+"&endDate=" + endDate
	  					+"&date="+new Date();
	  		}
	  		
			function pageDown(pageIndex) {
				var fileName = $("input[name='fileName']").val();
	  			var startDate = $("input[name='startDate']").val();
	  			var endDate = $("input[name='endDate']").val();
				window.location = path + "beshs/assignMeterDataFileAction!queryDataFilePage.do?pageIndex="+(pageIndex+1)
						+"&fileName="+encodeURIComponent(fileName)
						+"&startDate=" + startDate
						+"&endDate=" + endDate
						+"&date="+new Date();
	  		}
			
			function pageLocate(pageIndex) {
				var fileName = $("input[name='fileName']").val();
	  			var startDate = $("input[name='startDate']").val();
	  			var endDate = $("input[name='endDate']").val();
				window.location = path + "beshs/assignMeterDataFileAction!queryDataFilePage.do?pageIndex="+pageIndex
						+"&fileName="+encodeURIComponent(fileName)
						+"&startDate=" + startDate
						+"&endDate=" + endDate
						+"&date="+new Date();
			}
	  	</script>
	  	<div class="search_control">
	    	<div class="right">
	      		<div class="pages">
	      		<!-- 上一页 -->
	      			<s:if test="pageIndex==1">
	      				<a href="javascript:void(0)" class="disabled">Former Page</a>
	      			</s:if>
	      			<s:else>
	      				<a href="javascript:pageUp(<s:property value='pageIndex' />)">Former Page</a>
	      			</s:else>
	      		<!-- 页码 -->
	      			<s:if test="pageSize<=0">
	      			<!-- 若分页页数未初始化或为0，则只显示第一页 -->
	      				<a href="javascript:void(0)" class="current">1</a>
	      			</s:if>
	      			<s:elseif test="pageSize<=9">
	      			<!-- 页数在9页以内全显示 -->
	      				<s:bean name="org.apache.struts2.util.Counter" id="counter">
	      					<s:param name="first" value="1" />
	      					<s:param name="last" value="pageSize" />
	      					<s:iterator value="counter" var="index">
	      						<s:if test="#index==pageIndex">
		      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
		      					</s:if>
		      					<s:else>
		      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
		      					</s:else>
	      					</s:iterator>
	      				</s:bean>
	      			</s:elseif>
	      			<s:else>
	      			<!-- 页数在9页以上则部分显示 -->
	      				<s:if test="pageIndex<7">
	      				<!-- 页码小于7时，先显示前7页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="frontCounter">
	      						<s:param name="first" value="1" />
	      						<s:param name="last" value="7" />
	      						<s:iterator value="frontCounter" var="index">
	      							<s:if test="#index==pageIndex">
			      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
			      					</s:if>
			      					<s:else>
			      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
			      					</s:else>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      				<!-- 显示最后两页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="lastCounter">
	      						<s:param name="first" value="pageSize-1" />
	      						<s:param name="last" value="pageSize" />
	      						<s:iterator value="lastCounter" var="index">
	      							<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
	      						</s:iterator>
	      					</s:bean>
	      				</s:if>
	      				<s:elseif test="pageIndex>=7 && (pageSize-pageIndex)>2">
	      				<!-- 页码不小于7，但又不接近总页数时，分三部分显示：1-3、中间三页、最后一页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="frontCounter">
	      						<s:param name="first" value="1" />
	      						<s:param name="last" value="3" />
	      						<s:iterator value="frontCounter" var="index">
	      							<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      					<s:bean name="org.apache.struts2.util.Counter" id="middleCounter">
	      						<s:param name="first" value="pageIndex-1" />
	      						<s:param name="last" value="pageIndex+1" />
	      						<s:iterator value="middleCounter" var="index">
	      							<s:if test="#index==pageIndex">
			      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
			      					</s:if>
			      					<s:else>
			      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
			      					</s:else>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      					<a href="javascript:pageLocate(<s:property value='pageSize' />)"><s:property value="pageSize" /></a>
	      				</s:elseif>
	      				<s:else>
	      				<!-- 页码接近总页数，而且页码与总页数的差小于等于2时，分两部分显示：1-3、最后6页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="frontCounter">
	      						<s:param name="first" value="1" />
	      						<s:param name="last" value="3" />
	      						<s:iterator value="frontCounter" var="index">
	      							<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      					<s:bean name="org.apache.struts2.util.Counter" id="lastCounter">
	      						<s:param name="first" value="pageSize-5" />
	      						<s:param name="last" value="pageSize" />
	      						<s:iterator value="lastCounter" var="index">
	      							<s:if test="#index==pageIndex">
			      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
			      					</s:if>
			      					<s:else>
			      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
			      					</s:else>
	      						</s:iterator>
	      					</s:bean>
	      				</s:else>
	      			</s:else>
	      		<!-- 下一页 -->	
	      			<s:if test="pageSize>pageIndex">
	      				<a href="javascript:pageDown(<s:property value='pageIndex' />)">Next Page</a>
	      			</s:if>
	      			<s:else>
	      				<a href="javascript:void(0)" class="disabled">Next Page</a>
	      			</s:else>
	      		</div>
	    	</div>
	    	<div class="clear"></div>
	  	</div>
	  	<!-- 分页结束 -->
	</div>
  </body>
</html>
